﻿using System;
using System.ComponentModel;

namespace HalconDotNet
{
	/// <summary>Represents an instance of an event synchronization object.</summary>
	// Token: 0x02000039 RID: 57
	public class HEvent : HHandle
	{
		// Token: 0x0600053B RID: 1339 RVA: 0x0000883B File Offset: 0x00006A3B
		[EditorBrowsable(EditorBrowsableState.Never)]
		public HEvent() : base(HHandleBase.UNDEF)
		{
		}

		// Token: 0x0600053C RID: 1340 RVA: 0x0001E726 File Offset: 0x0001C926
		[EditorBrowsable(EditorBrowsableState.Never)]
		public HEvent(IntPtr handle) : base(handle)
		{
			this.AssertSemType();
		}

		// Token: 0x0600053D RID: 1341 RVA: 0x0001E735 File Offset: 0x0001C935
		[EditorBrowsable(EditorBrowsableState.Never)]
		public HEvent(HHandle handle) : base(handle)
		{
			this.AssertSemType();
		}

		// Token: 0x0600053E RID: 1342 RVA: 0x0001E744 File Offset: 0x0001C944
		private void AssertSemType()
		{
			base.AssertSemType("event");
		}

		// Token: 0x0600053F RID: 1343 RVA: 0x0001E751 File Offset: 0x0001C951
		internal static int LoadNew(IntPtr proc, int parIndex, int err, out HEvent obj)
		{
			obj = new HEvent(HHandleBase.UNDEF);
			return obj.Load(proc, parIndex, err);
		}

		// Token: 0x06000540 RID: 1344 RVA: 0x0001E76C File Offset: 0x0001C96C
		internal static int LoadNew(IntPtr proc, int parIndex, int err, out HEvent[] obj)
		{
			HTuple htuple;
			err = HTuple.LoadNew(proc, parIndex, err, out htuple);
			obj = new HEvent[htuple.Length];
			for (int i = 0; i < htuple.Length; i++)
			{
				obj[i] = new HEvent(HalconAPI.IsLegacyHandleMode() ? htuple[i].IP : htuple[i].H);
			}
			htuple.Dispose();
			return err;
		}

		/// <summary>
		///   Create an event synchronization object.
		///   Modified instance represents: Event synchronization object.
		/// </summary>
		/// <param name="attribName">Mutex attribute. Default: []</param>
		/// <param name="attribValue">Mutex attribute value. Default: []</param>
		// Token: 0x06000541 RID: 1345 RVA: 0x0001E7DC File Offset: 0x0001C9DC
		public HEvent(HTuple attribName, HTuple attribValue)
		{
			IntPtr proc = HalconAPI.PreCall(558);
			HalconAPI.Store(proc, 0, attribName);
			HalconAPI.Store(proc, 1, attribValue);
			HalconAPI.InitOCT(proc, 0);
			int num = HalconAPI.CallProcedure(proc);
			HalconAPI.UnpinTuple(attribName);
			HalconAPI.UnpinTuple(attribValue);
			num = base.Load(proc, 0, num);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(this);
		}

		/// <summary>
		///   Create an event synchronization object.
		///   Modified instance represents: Event synchronization object.
		/// </summary>
		/// <param name="attribName">Mutex attribute. Default: []</param>
		/// <param name="attribValue">Mutex attribute value. Default: []</param>
		// Token: 0x06000542 RID: 1346 RVA: 0x0001E83C File Offset: 0x0001CA3C
		public HEvent(string attribName, string attribValue)
		{
			IntPtr proc = HalconAPI.PreCall(558);
			HalconAPI.StoreS(proc, 0, attribName);
			HalconAPI.StoreS(proc, 1, attribValue);
			HalconAPI.InitOCT(proc, 0);
			int num = HalconAPI.CallProcedure(proc);
			num = base.Load(proc, 0, num);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(this);
		}

		/// <summary>
		///   Clear the event synchronization object.
		///   Instance represents: Event synchronization object.
		/// </summary>
		// Token: 0x06000543 RID: 1347 RVA: 0x0001E890 File Offset: 0x0001CA90
		public void ClearEvent()
		{
			IntPtr proc = HalconAPI.PreCall(554);
			base.Store(proc, 0);
			int procResult = HalconAPI.CallProcedure(proc);
			HalconAPI.PostCall(proc, procResult);
			GC.KeepAlive(this);
		}

		/// <summary>
		///   Unlock an event synchronization object. 
		///   Instance represents: Event synchronization object.
		/// </summary>
		// Token: 0x06000544 RID: 1348 RVA: 0x0001E8C4 File Offset: 0x0001CAC4
		public void SignalEvent()
		{
			IntPtr proc = HalconAPI.PreCall(555);
			base.Store(proc, 0);
			int procResult = HalconAPI.CallProcedure(proc);
			HalconAPI.PostCall(proc, procResult);
			GC.KeepAlive(this);
		}

		/// <summary>
		///   Lock an event synchronization object only if it is unlocked.
		///   Instance represents: Event synchronization object.
		/// </summary>
		/// <returns>Object already locked?</returns>
		// Token: 0x06000545 RID: 1349 RVA: 0x0001E8F8 File Offset: 0x0001CAF8
		public int TryWaitEvent()
		{
			IntPtr proc = HalconAPI.PreCall(556);
			base.Store(proc, 0);
			HalconAPI.InitOCT(proc, 0);
			int num = HalconAPI.CallProcedure(proc);
			int result;
			num = HalconAPI.LoadI(proc, 0, num, out result);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(this);
			return result;
		}

		/// <summary>
		///   Lock an event synchronization object.
		///   Instance represents: Event synchronization object.
		/// </summary>
		// Token: 0x06000546 RID: 1350 RVA: 0x0001E940 File Offset: 0x0001CB40
		public void WaitEvent()
		{
			IntPtr proc = HalconAPI.PreCall(557);
			base.Store(proc, 0);
			int procResult = HalconAPI.CallProcedure(proc);
			HalconAPI.PostCall(proc, procResult);
			GC.KeepAlive(this);
		}

		/// <summary>
		///   Create an event synchronization object.
		///   Modified instance represents: Event synchronization object.
		/// </summary>
		/// <param name="attribName">Mutex attribute. Default: []</param>
		/// <param name="attribValue">Mutex attribute value. Default: []</param>
		// Token: 0x06000547 RID: 1351 RVA: 0x0001E974 File Offset: 0x0001CB74
		public void CreateEvent(HTuple attribName, HTuple attribValue)
		{
			this.Dispose();
			IntPtr proc = HalconAPI.PreCall(558);
			HalconAPI.Store(proc, 0, attribName);
			HalconAPI.Store(proc, 1, attribValue);
			HalconAPI.InitOCT(proc, 0);
			int num = HalconAPI.CallProcedure(proc);
			HalconAPI.UnpinTuple(attribName);
			HalconAPI.UnpinTuple(attribValue);
			num = base.Load(proc, 0, num);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(this);
		}

		/// <summary>
		///   Create an event synchronization object.
		///   Modified instance represents: Event synchronization object.
		/// </summary>
		/// <param name="attribName">Mutex attribute. Default: []</param>
		/// <param name="attribValue">Mutex attribute value. Default: []</param>
		// Token: 0x06000548 RID: 1352 RVA: 0x0001E9D4 File Offset: 0x0001CBD4
		public void CreateEvent(string attribName, string attribValue)
		{
			this.Dispose();
			IntPtr proc = HalconAPI.PreCall(558);
			HalconAPI.StoreS(proc, 0, attribName);
			HalconAPI.StoreS(proc, 1, attribValue);
			HalconAPI.InitOCT(proc, 0);
			int num = HalconAPI.CallProcedure(proc);
			num = base.Load(proc, 0, num);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(this);
		}
	}
}
